<?php

	include("pub/conn.php");
	include("pub/functions.php");

	$do = isset($_POST['do']) ? $_POST['do'] : '';

	// 提取用户基础信息，有权限的显示权限名
	if($do == "getUserInfo"){

		$sql = "
			SELECT u.*, r.title
			from tj.operation_users u
			left join tj.operation_right r on u.right_id = r.id
		";	
	}

	// 权限列表，参数，user_type
	if($do == "getRightId"){
		$user_type = isset($_POST['user_type']) ? $_POST['user_type'] : '';
		$sql = "
			SELECT r.id, r.title
			from tj.operation_right r
			where r.user_type = $user_type
		";	
	}

	// 设置权限
	if($do == "setRight"){
		$user_id = isset($_POST['user_id']) ? $_POST['user_id'] : '';
		$user_type = isset($_POST['user_type']) ? $_POST['user_type'] : '';
		$right_id = isset($_POST['right_id']) ? $_POST['right_id'] : 0;
		$sql = "
			UPDATE tj.operation_users u
			set u.user_type = $user_type, u.right_id = $right_id
			where u.user_id = $user_id
		";
	}

	// if($do == "ty_classes_table"){
	// 	$mon = isset($_POST['mon']) ? $_POST['mon'] : ''; // 查询的月份
	// 	$count_type = isset($_POST['count_type']) ? $_POST['count_type'] : 'gym'; // count_type 取值： city, gym
	// 	if($count_type == 'city'){
	// 		$target = 'city';
	// 		$grouper = 'city_id';
	// 	}else{
	// 		$target = '`name`';
	// 		$grouper = 'g.id';
	// 	}
	// 	//$id = isset($_POST['id']) ? $_POST['id'] : ''; // id 对应各种type取值下的对应值
	// 	$sql = "
	// 		SELECT date_format(d.`day`, '%Y-%m') as `mon`, g.$target as target, sum(d.user_classes) pre, sum(d.ty_user_classes) ty_pre
	// 		from tj.gym_days d
	// 		inner join gym g on d.gym_id = g.id
	// 		inner join region_gym rg on rg.gym_id = g.id
	// 		where date_format(d.`day`, '%Y-%m') = '$mon'
	// 		group by $grouper
	// 	";
	// }


	echo query_sql($sql, $conn);

?>